{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 合并相似性矩阵\n",
    "\n",
    "此代码目的是将多个group中的相似性矩阵合并。\n",
    "\n",
    "This code aims to merge the similarity matrix from several groups"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from scipy.sparse import *\n",
    "import scipy\n",
    "import os\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "path = 'tmpData/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "save success for 10 batch\n",
      "-------------------------\n",
      "save success for 11 batch\n",
      "-------------------------\n"
     ]
    }
   ],
   "source": [
    "lenth = 359850\n",
    "for i in range(0, 12):\n",
    "    mat = None\n",
    "    start = lenth * i\n",
    "    end = lenth * (i + 1)\n",
    "    count = 0\n",
    "    for name in os.listdir('tmpData/'):\n",
    "        if name[-3:] == 'npz':\n",
    "            if mat == None:\n",
    "                mat = load_npz(path + name)[start: end]\n",
    "            else:\n",
    "                mat += load_npz(path + name)[start: end]\n",
    "        count += 1\n",
    "    scipy.sparse.save_npz('commonMatrix/common_matrix_from_%d_to_%d.npz'%(start, end), mat)\n",
    "    print('save success for %d batch'%i)\n",
    "    print('-------------------------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
